// components/my-avatar/my-avatar.js

import {code} from '../../utils/result'
import {host} from '../../config'
let app =getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    userInfo:{
      type : Object,
    }
  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    bindDeleteAccount(){
      let userInfo = this.properties.userInfo
      wx.showActionSheet({
        itemList: ["注销账户"],
        alertText: "注销",
        success(res){
          console.log(res)
          if(res.tapIndex == 0){
            wx.showModal({
              title: '注销账号',
              content: '您即将注销账号',
              complete: (res) => {
                if (res.confirm) {
                  app.globalData.userInfo = null
                  wx.request({
                    url: host + "users/deleteAccount?userId=" + userInfo.userId,
                    method: 'DELETE',
                    success(res){
                      console.log(res)
                      wx.clearStorageSync()
                      app.getUserInfo(function(){})
                    }
                  })
                }
              }
            })
           
          }
        }
      })
      
    }
  }
})
